#include("/common/_layout.html")
#@layout()
#define layoutHead()
	<link rel="stylesheet" type="text/css" href="/static/other/area/css/city-picker.css">
	<link rel="stylesheet" type="text/css" href="/static/other/selectpage/selectpage.css">
	<title>机构编辑</title>
	<style>
		.teacher-add{ display: ; }
		.teacher-label{ }
	</style>
#end
#define layoutBody()
	<body>
		<div class="page-content-wrap">
				<form class="layui-form" lay-filter="formedit">
					<input type="hidden" name="org_id">
					<div class="layui-tab" style="margin: 0;">
						<ul class="layui-tab-title">
							<li><a href="javascript:window.history.back();">机构列表</a></li>
							<li class="layui-this">机构编辑</li>
						</ul>
						<input type="hidden" name="user_id">
						<div class="layui-tab-content">
							<div class="layui-tab-item"></div>
							<div class="layui-tab-item layui-show">
								<div class="layui-form-item">
									<label class="layui-form-label">机构名称：</label>
									<div class="layui-input-block">
										<input type="text" name="org_name" required lay-verify="required" placeholder="请输入机构名称" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item" style="">
									<label class="layui-form-label">机构热线：</label>
									<div class="layui-input-block">
										<input type="text" name="link_tel" required lay-verify="required" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">省/市/县：</label>
									<div class="layui-input-block" id="divapprole">
										<input id="area_id" name="area_id" type="hidden" value="">
										<input id="area_ids" name="area_ids" type="hidden" value="">
										<input type="text" id="area_names" name="area_names" valid="area_id" valids="area_ids" placeholder="点击选择省/市/区/县" value="" readonly data-toggle="city-picker" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">地址：</label>
									<div class="layui-input-block">
										<input type="text" name="area_address" required lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input">
									</div>
								</div>
								<hr>
								<div class="layui-form-item" style="display:none;">
									<label class="layui-form-label">管理员：</label>
									<div class="layui-input-block">
										<input type="text" id="admin_userid" name="admin_userid" required lay-verify="" placeholder="推荐园长做为管理员" autocomplete="off" class="layui-input" style="width:260px;">
										<span class="layui-btn layui-btn-normal" id="btn_add_teacher">新增</span>
										<input type="hidden" id="add_teacher" name="add_teacher" value="0">
									</div>
								</div>
								<div class="layui-form-item teacher-add">
									<label class="layui-form-label teacher-label">园长姓名：</label>
									<div class="layui-input-block">
										<input type="text" name="teacher_name" placeholder="用户真实姓名" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item teacher-add">
									<label class="layui-form-label teacher-label">园长手机：</label>
									<div class="layui-input-block">
										<input type="text" name="teacher_mobile" placeholder="默认做为 [教育机构控制台] 登录名" autocomplete="off" class="layui-input">
									</div>
								</div>
								<div class="layui-form-item teacher-add">
									<label class="layui-form-label teacher-label">园长密码：</label>
									<div class="layui-input-block">
										<input type="text" name="teacher_pwd" placeholder="默认做为 [教育机构控制台] 登录密码" autocomplete="off" class="layui-input">
									</div>
								</div>
								<hr>
								<div class="layui-form-item">
									<label class="layui-form-label">状态：</label>
									<div class="layui-input-block">
										<select name="org_state" lay-verify="required">
											<option value="1">启用</option>
											<option value="0">禁用</option>
										</select>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item" style="padding-left: 10px;">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即提交</button>
							
						</div>
					</div>
				</form>
		</div>
		<!-- #[[ -->
		<script src="/static/other/area/js/city-picker-simple.js"></script>
		<script id="tplapprole" type="text/html">
		{{#  layui.each(d.listapp, function(index, item){ }}
			{{#  if(item.app_state === 1){ }}
				<div style="border:1px solid #ccc; margin-top: 10px; padding: 10px;">
					<input type="checkbox" name="app_id_{{ item.app_id }}" title="{{ item.app_name }}">
					<hr>
					{{#  layui.each(d.listrole, function(index2, item2){ }}
						<input type="checkbox" name="role_id_{{ item.app_id }}_{{ item2.role_id }}" title="{{ item2.role_name }}" lay-skin="primary">
					{{#  }); }}	
				</div>
			{{#  } }} 
		{{#  }); }}	
		</script>
		<!-- ]]# -->
		<script src="/static/js/jquery.formHelp.js" type="text/javascript" charset="utf-8"></script>
	<script src="/static/other/selectpage/selectpage.min.js" type="text/javascript" charset="utf-8"></script>
		<script>
			// 下拉框分页 - 初始化
			$('#admin_userid').selectPage({
				showField : 'teacher_name',
				keyField : 'user_id',
				data : '/api/teacher/getPage?org_id='+getUrlParam('id'),
				selectOnly : true,
				eAjaxSuccess : function(d){
					var result;
					if(d && d.hasOwnProperty('pageData') && d.pageData.hasOwnProperty('list')) result = d.pageData;
					else result = undefined;
					return result;
				},
				eSelect : function(data){ 	
				}
			});
			
			$('#btn_add_teacher').click(function(){
				var s = $('div.teacher-add').first().css('display');
				//console.log(s);
				if (s == "none"){
					s = 'block';
					$('#add_teacher').val('1');
					$('#btn_add_teacher').html('取消');
				}else{
					s = 'none';
					$('#add_teacher').val('0');
					$('#btn_add_teacher').html('新增');
				}
				$('div.teacher-add').css('display', s);
			});
			
			layui.use(['form', 'layer', 'laytpl'], function() {
				var form = layui.form();
				var layer = layui.layer;
				var laytpl = layui.laytpl;
				// 表单验证
				form.verify({
					username: function(value, item){ //value：表单的值、item：表单的DOM对象
						if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
							return '用户名不能有特殊字符';
						}
						if(/(^\_)|(\__)|(\_+$)/.test(value)){
							return '用户名首尾不能出现下划线\'_\'';
						}
						if(/^\d+\d+\d$/.test(value)){
							return '用户名不能全为数字';
						}
					}
					,passwd: [
						/^[\S]{6,12}$/
						,'密码必须6到12位，且不能出现空格'
					] 
				});

				//监听提交
				form.on('submit(formDemo)', function(formData){
					//console.log(formData.field);
					sendPost("/api/aiorg/save", formData.field, function(res) {
						layer.alert(res.msg, {
							title: '信息提示'
						}, function(idx){
							if (res.code==200){
								//window.location.href = '/admin/list/org?app_id=#(login_app_id)';
								window.history.back();
							}
							layer.close(idx);
						});
					});
					return false;
				});

				// 页面初始化
				function page_init(){
					var id = getUrlParam('id');

					// 加载初始化编辑数据
					sendGet("/api/aiorg/getOrg", {
						id : getUrlParam("id")
					}, function(res) {
						//console.log(res);
						// 初始化编辑数据
						if (res.hasOwnProperty("orginfo")) {
							//console.log(res.orginfo.area_names);
							$("form.layui-form").setForm(res.orginfo);
							$('#admin_userid_text').val(res.orginfo.teacher_name);
							$("#area_names").citypicker("refresh");
							$('input[name="teacher_pwd"]').attr('placeholder', '不修改，请置空');
						}else{
							$('#add_teacher').val('1');
						}
						form.render();
						
						
					});
				}

				page_init();
			});
			
			
					
		</script>
	</body>

#end